//
// Created by Administrator on 2024/5/.
// 二分查找 找随便一个相同值的索引 没有就返回-1
//

#include <iostream>
#include <vector>

using namespace std;

int search(vector<int> l, int x)
{
    int left = 0, right = l.size() - 1, m;
    while (left <= right)
    {
        m = (left + right) / 2;
        if (l[m] == x)
        {
            return m;
        } else if (l[m] < x)
        {
            left = m + 1;
        } else
        {
            right = m - 1;
        }
    }
    return -1;
}

int main()
{
    vector<int> n = {-11, -5, 0,0, 2, 2,2,3, 5, 7, 8, 10, 13, 70, 79};
    cout << search(n, 2);
    return 0;
}